﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

using ModelLayer;

namespace DBLayer
{
    public class DBShowRoom
    {
        private SqlConnection con;

        public DBShowRoom()
        {
            con = DBConnection.getInstance().getDBCon();
        }

        /**
         * Retrieves a showroom from the databse, based on the show´s id
         * test
         * */
        public ShowRoom GetShowRoomOnShowId(int show_Id)
        {
            ShowRoom room = null;

            SqlDataReader reader = null;

            SqlParameter idParam = new SqlParameter("@show_Id", SqlDbType.Int);
            idParam.Value = show_Id;

            SqlCommand command = new SqlCommand();
            command.Connection = con;
            command.CommandText = "SELECT RoomNumber, Row, Col FROM ShowRoom " +
                                    "INNER JOIN show " +
                                    "ON ShowRoom.RoomNumber = Show.ShowRoom_id " +
                                    "WHERE id = @show_Id";
            command.Parameters.Add(idParam);
            
            try
            {
               
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    room = new ShowRoom(reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
                }

                reader.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }

            return room;
        }
    }
}
